package com.company.zoj;

import java.util.*;

/**
 * Created by v on 17-6-6.
 */
public class ZojTest1516 {
    private static boolean[][] map;
    private static int n;
    private static int m;
    private static boolean[] isVisited;

    private static ArrayList<LinkedList<Integer>> matrix;

    private static void init(){
        matrix=new ArrayList<LinkedList<Integer>>();
        for(int i=0;i<n*m;i++){
            matrix.add(new LinkedList<Integer>());
        }

        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(!isVisited[i*m+j]){
                    add(i*m+j);
                }
            }
        }
    }

    private static int solve(){
        int sum=0;
        Queue<Integer> queue=new LinkedList<>();

        for(int i=0;i<isVisited.length;i++){
            if(!isVisited[i]) {
                if (matrix.get(i).size() == 1&&!isVisited[i]) {
                    queue.offer(i);
                }
            }
        }

        int current=0;

        while (current<isVisited.length){
            int index=0;
            if(queue.isEmpty()){
                while (current<isVisited.length){
                    if(isVisited[current]){
                        current++;
                        continue;
                    }

                    if(matrix.get(current).size()>0){
                        index=current;
                        break;
                    }else {
                        isVisited[current]=true;
                    }
                }
                if(current>=isVisited.length){
                    break;
                }
            }else {
                index=queue.poll();
                if(isVisited[index]){
                    continue;
                }
            }
            if(matrix.get(index).size()==0){
                isVisited[index]=true;
                continue;
            }

            sum++;
            for(Integer j:matrix.get(index)){
                matrix.get(j).remove(new Integer(index));
                if(matrix.get(j).size()==1&&!isVisited[j]){
                    queue.offer(j);
                }
            }
            isVisited[index]=true;
            index=matrix.get(index).get(0);
            isVisited[index]=true;
            for(Integer j:matrix.get(index)){
                matrix.get(j).remove(new Integer(index));
                if(matrix.get(j).size()==1){
                    queue.offer(j);
                }
            }
        }

        return sum;
    }

    private static void add(int current){
        if(current-m>=0&&!map[current/m-1][current%m]){
            matrix.get(current).add(current-m);
        }

        if(current+m<m*n&&!map[current/m+1][current%m]){
            matrix.get(current).add(current+m);
        }

        if(current%m>0&&!map[current/m][current%m-1]){
            matrix.get(current).add(current-1);
        }

        if(current%m<m-1&&!map[current/m][current%m+1]){
            matrix.get(current).add(current+1);
        }
    }

    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);

        while (true){
            n=input.nextInt();
            m=input.nextInt();
            if(n==0&&m==0){
                break;
            }
            map=new boolean[n][m];
            isVisited=new boolean[n*m];

            int black=input.nextInt();
            for(int i=0;i<black;i++){
                int row=input.nextInt()-1;
                int column=input.nextInt()-1;

                map[row][column]=true;
                isVisited[row*m+column]=true;
            }
            init();
            System.out.println(solve());
        }
    }
}
